package com.ymatou.iapi.selleronline.testcase;

import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.selleronline.parameter.OnlinestatusOpBean;
import com.ymatou.iapi.selleronline.service.OnlinestatusOpCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.database.sqlwapper.UserSafeWapper;
import com.ymttest.utils.YMTDateUtil;
/**
*买手在线状态
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_OnlinestatusOp{
	private static OnlinestatusOpBean onlinestatusopBean;
	private static OnlinestatusOpCall onlinestatusopCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("买手在线状态");
	}

	@Before
	public void caseUp() {
		onlinestatusopBean=new OnlinestatusOpBean();
		onlinestatusopCall=new OnlinestatusOpCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(onlinestatusopCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_OnlinestatusOp_001() {
		Logger.start(true,"买手（主/子）账号PC客服后台设置,为在线,PCIMChangStatus10001:1");
		try {
			onlinestatusopBean.setOpType("10001");
			onlinestatusopBean.setOp("1");
			onlinestatusopBean.setUserId(93);
			onlinestatusopBean.setOpTime(YMTDateUtil.getSysTime("yyyy-MM-dd HH:mm:ss"));
			onlinestatusopBean.setAppSource("autotest");
			onlinestatusopCall.setData(onlinestatusopBean);
			onlinestatusopCall.callService();
			Logger.verifyEquals("true", onlinestatusopCall.getString("Success"), "验证Success");
			Logger.verifyEquals("ok", onlinestatusopCall.getString("Result"), "验证Result");
			verifyDB(onlinestatusopBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_OnlinestatusOp_002() {
		Logger.start(true,"买手（主/子）账号PC客服后台设置,为隐身,PCIMChangStatus10001:0");
		try {
			onlinestatusopBean.setOpType("10001");
			onlinestatusopBean.setOp("0");
			onlinestatusopBean.setUserId(93);
			onlinestatusopBean.setOpTime(YMTDateUtil.getSysTime("yyyy-MM-dd HH:mm:ss"));
			onlinestatusopBean.setAppSource("autotest");
			onlinestatusopCall.setData(onlinestatusopBean);
			onlinestatusopCall.callService();
			Logger.verifyEquals("true", onlinestatusopCall.getString("Success"), "验证Success");
			Logger.verifyEquals("ok", onlinestatusopCall.getString("Result"), "验证Result");
			verifyDB(onlinestatusopBean);
			//TODO 10002也变成0
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_OnlinestatusOp_003() {
		Logger.start(true,"买手手机开启了接收买手APPPUSH消息的权限，AppReceiveMsgOp20002:1");
		try {
			onlinestatusopBean.setOpType("20002");
			onlinestatusopBean.setOp("1");
			onlinestatusopBean.setUserId(93);
			onlinestatusopBean.setOpTime(YMTDateUtil.getSysTime("yyyy-MM-dd HH:mm:ss"));
			onlinestatusopBean.setAppSource("autotest");
			onlinestatusopCall.setData(onlinestatusopBean);
			onlinestatusopCall.callService();
			Logger.verifyEquals("true", onlinestatusopCall.getString("Success"), "验证Success");
			Logger.verifyEquals("ok", onlinestatusopCall.getString("Result"), "验证Result");
			verifyDB(onlinestatusopBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_OnlinestatusOp_004() {
		Logger.start(true,"买手手机开启了接收买手APPPUSH消息的权限，AppReceiveMsgOp20002:0");
		try {
			onlinestatusopBean.setOpType("20002");
			onlinestatusopBean.setOp("0");
			onlinestatusopBean.setUserId(93);
			onlinestatusopBean.setOpTime(YMTDateUtil.getSysTime("yyyy-MM-dd HH:mm:ss"));
			onlinestatusopBean.setAppSource("autotest");
			onlinestatusopCall.setData(onlinestatusopBean);
			onlinestatusopCall.callService();
			Logger.verifyEquals("true", onlinestatusopCall.getString("Success"), "验证Success");
			Logger.verifyEquals("ok", onlinestatusopCall.getString("Result"), "验证Result");
			verifyDB(onlinestatusopBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_OnlinestatusOp_005() {
		Logger.start(true,"买手APP认证服务TOKEN认证开启，AppTokenAuth30001:1");
		try {
			onlinestatusopBean.setOpType("30001");
			onlinestatusopBean.setOp("1");
			onlinestatusopBean.setUserId(93);
			onlinestatusopBean.setOpTime(YMTDateUtil.getSysTime("yyyy-MM-dd HH:mm:ss"));
			onlinestatusopBean.setAppSource("autotest");
			onlinestatusopCall.setData(onlinestatusopBean);
			onlinestatusopCall.callService();
			Logger.verifyEquals("true", onlinestatusopCall.getString("Success"), "验证Success");
			Logger.verifyEquals("ok", onlinestatusopCall.getString("Result"), "验证Result");
			verifyDB(onlinestatusopBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_OnlinestatusOp_006() {
		Logger.start(true,"买手APP认证服务TOKEN认证关闭，AppTokenAuth30001:0");
		try {
			onlinestatusopBean.setOpType("30001");
			onlinestatusopBean.setOp("0");
			onlinestatusopBean.setUserId(93);
			onlinestatusopBean.setOpTime(YMTDateUtil.getSysTime("yyyy-MM-dd HH:mm:ss"));
			onlinestatusopBean.setAppSource("autotest");
			onlinestatusopCall.setData(onlinestatusopBean);
			onlinestatusopCall.callService();
			Logger.verifyEquals("true", onlinestatusopCall.getString("Success"), "验证Success");
			Logger.verifyEquals("ok", onlinestatusopCall.getString("Result"), "验证Result");
			verifyDB(onlinestatusopBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_OnlinestatusOp_007() {
		Logger.start(true,"登录买手（主/子）账号PC客服后台PCIMChangStatus10002:1");
		try {
			onlinestatusopBean.setOpType("10002");
			onlinestatusopBean.setOp("1");
			onlinestatusopBean.setUserId(93);
			onlinestatusopBean.setOpTime(YMTDateUtil.getSysTime("yyyy-MM-dd HH:mm:ss"));
			onlinestatusopBean.setAppSource("autotest");
			onlinestatusopCall.setData(onlinestatusopBean);
			onlinestatusopCall.callService();
			Logger.verifyEquals("true", onlinestatusopCall.getString("Success"), "验证Success");
			Logger.verifyEquals("ok", onlinestatusopCall.getString("Result"), "验证Result");
			verifyDB(onlinestatusopBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_OnlinestatusOp_008() {
		Logger.start(true,"登出买手（主/子）账号PC客服后台PCIMChangStatus10002:0");
		try {
			onlinestatusopBean.setOpType("10002");
			onlinestatusopBean.setOp("0");
			onlinestatusopBean.setUserId(93);
			onlinestatusopBean.setOpTime(YMTDateUtil.getSysTime("yyyy-MM-dd HH:mm:ss"));
			onlinestatusopBean.setAppSource("autotest");
			onlinestatusopCall.setData(onlinestatusopBean);
			onlinestatusopCall.callService();
			Logger.verifyEquals("true", onlinestatusopCall.getString("Success"), "验证Success");
			Logger.verifyEquals("ok", onlinestatusopCall.getString("Result"), "验证Result");
			verifyDB(onlinestatusopBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_OnlinestatusOp_009() {
		Logger.start(true,"买手APP运行模式（IOS）前台运行,AppRunType40001:1");
		try {
			onlinestatusopBean.setOpType("40001");
			onlinestatusopBean.setOp("1");
			onlinestatusopBean.setUserId(93);
			onlinestatusopBean.setOpTime(YMTDateUtil.getSysTime("yyyy-MM-dd HH:mm:ss"));
			onlinestatusopBean.setAppSource("autotest");
			onlinestatusopCall.setData(onlinestatusopBean);
			onlinestatusopCall.callService();
			Logger.verifyEquals("true", onlinestatusopCall.getString("Success"), "验证Success");
			Logger.verifyEquals("ok", onlinestatusopCall.getString("Result"), "验证Result");
			verifyDB(onlinestatusopBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_OnlinestatusOp_010() {
		Logger.start(true,"买手APP运行模式（IOS）后台运行,AppRunType40001:0");
		try {
			onlinestatusopBean.setOpType("40001");
			onlinestatusopBean.setOp("0");
			onlinestatusopBean.setUserId(93);
			onlinestatusopBean.setOpTime(YMTDateUtil.getSysTime("yyyy-MM-dd HH:mm:ss"));
			onlinestatusopBean.setAppSource("autotest");
			onlinestatusopCall.setData(onlinestatusopBean);
			onlinestatusopCall.callService();
			Logger.verifyEquals("true", onlinestatusopCall.getString("Success"), "验证Success");
			Logger.verifyEquals("ok", onlinestatusopCall.getString("Result"), "验证Result");
			verifyDB(onlinestatusopBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_OnlinestatusOp_011() {
		Logger.start(true,"买手登录APP，AppLoginStatus50001:1");
		try {
			onlinestatusopBean.setOpType("50001");
			onlinestatusopBean.setOp("1");
			onlinestatusopBean.setUserId(93);
			onlinestatusopBean.setOpTime(YMTDateUtil.getSysTime("yyyy-MM-dd HH:mm:ss"));
			onlinestatusopBean.setAppSource("autotest");
			onlinestatusopCall.setData(onlinestatusopBean);
			onlinestatusopCall.callService();
			Logger.verifyEquals("true", onlinestatusopCall.getString("Success"), "验证Success");
			Logger.verifyEquals("ok", onlinestatusopCall.getString("Result"), "验证Result");
			verifyDB(onlinestatusopBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_OnlinestatusOp_012() {
		Logger.start(true,"买手退出APP，AppLoginStatus50001:0");
		try {
			onlinestatusopBean.setOpType("50001");
			onlinestatusopBean.setOp("0");
			onlinestatusopBean.setUserId(93);
			onlinestatusopBean.setOpTime(YMTDateUtil.getSysTime("yyyy-MM-dd HH:mm:ss"));
			onlinestatusopBean.setAppSource("autotest");
			onlinestatusopCall.setData(onlinestatusopBean);
			onlinestatusopCall.callService();
			Logger.verifyEquals("true", onlinestatusopCall.getString("Success"), "验证Success");
			Logger.verifyEquals("ok", onlinestatusopCall.getString("Result"), "验证Result");
			verifyDB(onlinestatusopBean);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	@Ignore
	//不传userid默认0
	public void Tc_OnlinestatusOp_013() {
		Logger.start(true,"不输入参数userid,失败");
		try {
			onlinestatusopBean.setOpType("50001");
			onlinestatusopBean.setOp("1");
//			onlinestatusopBean.setUserId(93);
			onlinestatusopBean.setOpTime(YMTDateUtil.getSysTime("yyyy-MM-dd HH:mm:ss"));
			onlinestatusopCall.setData(onlinestatusopBean);
			onlinestatusopCall.callService();
			Logger.verifyEquals("false", onlinestatusopCall.getString("Success"), "验证Success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_OnlinestatusOp_014() {
		Logger.start(true,"不输入参数op,失败");
		try {
			onlinestatusopBean.setOpType("50001");
//			onlinestatusopBean.setOp("1");
			onlinestatusopBean.setUserId(93);
			onlinestatusopBean.setOpTime(YMTDateUtil.getSysTime("yyyy-MM-dd HH:mm:ss"));
			onlinestatusopCall.setData(onlinestatusopBean);
			onlinestatusopCall.callService();
			Logger.verifyEquals("false", onlinestatusopCall.getString("Success"), "验证Success");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_OnlinestatusOp_015() {
		Logger.start(true,"不输入参数optype,失败");
		try {
//			onlinestatusopBean.setOpType("50001");
			onlinestatusopBean.setOp("1");
			onlinestatusopBean.setUserId(93);
			onlinestatusopBean.setOpTime(YMTDateUtil.getSysTime("yyyy-MM-dd HH:mm:ss"));
			onlinestatusopCall.setData(onlinestatusopBean);
			onlinestatusopCall.callService();
			Logger.verifyEquals("false", onlinestatusopCall.getString("Success"), "验证Success");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_OnlinestatusOp_016() {
		Logger.start(true,"不输入参数OpTime,失败");
		try {
			onlinestatusopBean.setOpType("50001");
			onlinestatusopBean.setOp("1");
			onlinestatusopBean.setUserId(93);
//			onlinestatusopBean.setOpTime(YMTDateUtil.getSysTime("yyyy-MM-dd HH:mm:ss"));
			onlinestatusopCall.setData(onlinestatusopBean);
			onlinestatusopCall.callService();
			Logger.verifyEquals("false", onlinestatusopCall.getString("Success"), "验证Success");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	/**
	 * @param oob
	 * @return Command
	 * @throws InterruptedException 
	 */
	private void verifyDB(OnlinestatusOpBean oob) throws InterruptedException {
		UserSafeWapper wapper = new UserSafeWapper();
		Map<String,Object> m=wapper.selectSelleronlineStatus(oob.getUserId(), oob.getOpType()).get(0);
		Logger.debug(m);
		//{Op=1, LastUpdateTime=2018-10-10 10:05:47.0, UserId=93, CreateTime=2016-09-07 14:40:28.0, OpDescript=null, OpType=10001, OpTime=2018-10-10 10:05:47.0, AppSource=autotest}
		Logger.verifyEquals(oob.getUserId(), m.get("UserId"), "验证UserId");
		Logger.verifyEquals(oob.getOp(), m.get("Op"), "验证op");
		Logger.verifyEquals(oob.getOpTime().substring(0,19), m.get("OpTime").toString().substring(0,19), "验证OpTime");
		Logger.verifyEquals(oob.getOpType(), m.get("OpType"), "验证OpType");
		Logger.verifyEquals(oob.getAppSource(), m.get("AppSource"), "验证AppSource");
	}

	
}